
#ifndef __PinYin_MATCH_H__
#define __PinYin_MATCH_H__


class PinYinMatch
{
public:


	static bool match(CString const& strInput, CString const& strPinYin)
	{
		int count = strInput.GetLength();
		

		CString strFullPyin;
		CString strSimplePyin;

		GetPinYin(strPinYin, strFullPyin, strSimplePyin);

		if ( strInput.GetLength() > 1 )
		{
			return	StrStrI(strSimplePyin, strInput) != NULL ||
				StrStrI(strFullPyin, strInput) != NULL ;
		}
		else
		{
			return	StrStrI(strSimplePyin, strInput) != NULL;
		}


	}

public:
	static BOOL _GetSection(CString const& strPinYin, int sec, CString& strSection)
	{
		int p = 0;
		for (int i = 0; i < sec; ++i)
		{
			p = strPinYin.Find(']', p);
			if (p < 0)
			{
				return FALSE;
			}
			p += 1;
		}

		int e = strPinYin.Find(']', p);
		if (e < 0)
			return FALSE;
		CString strSec = strPinYin.Mid(p + 1, e - p - 1);
		strSection = strSec;
		return TRUE;
	}

public:
	static void GetPinYin(CString const& pinyin, CString& strFull, CString& strSimple)
	{
		int sec = 0;
		CString strSec;
		while (_GetSection(pinyin, sec, strSec))
		{
			sec++;
			strFull += strSec;
			strSimple += strSec[0];
		}

	}

};

#endif